package cn.fl.riskctrl.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.product.service.ISplInfoService;
import cn.fl.riskctrl.service.IRskCtrlCfgService;
import cn.fl.riskctrl.vo.RskCtrlCfgDVO;
import cn.fl.riskctrl.vo.RskCtrlCfgMVO;
import cn.fl.system.constant.SysLogConstant;
import fl.constant.facade.framework.constant.DictionaryConstant;
import fl.riskctrl.facade.riskctrl.condition.RskCtrlCfgDQC;
import fl.riskctrl.facade.riskctrl.condition.RskCtrlCfgMQC;

/**
 * Created by Administrator on 2017/6/5.
 */
@Controller
@RequestMapping("/riskctrl/rskctrlcfg")
public class RskCtrlCfgController {

	private static final Logger logger = LoggerFactory.getLogger(RskCtrlMDController.class);

    /**
     * 第三方征信公司信息服务
     */
    @Autowired
    private IRskCtrlCfgService rskCtrlCfgService;

    /**
     * PrdSplInfo 服务层BEAN
     */
    @Autowired
    private ISplInfoService prdSplInfoService;

    /**
     * 数据字典服务
     */
    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;

    /**
     * 到征信配置信息主页面
     */
    @RequestMapping(value = "/toMainPage.do", method = { RequestMethod.GET })
    public ModelAndView toMainPage(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toMainPage", " 跳转到第三方征信风控配置主表信息页面.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        ModelAndView view = new ModelAndView("riskctrl/riskctrlcfg/riskCtrlCfgMain");
        // 事业部
        // List<KeyValueVO> searchBuOrgList = this.prdSplInfoService.searchBuOrgCdList();

        // 征信规则业务编码
        String codeGrpCd = PropertiesCacheUtils.getProperty(DictionaryConstant.RC_CFG_BUS_CD);
        List<KeyValueVO> searchBuOrgList = this.sysDictionaryApiService.getKvList(codeGrpCd, CurrentThreadContext.getFlServiceSysCd(), "0000");
        view.addObject("searchBuOrgList", searchBuOrgList);

        //系统编码
        codeGrpCd = PropertiesCacheUtils.getProperty(DictionaryConstant.CODE_SYS_CD);
        List<KeyValueVO> sysCodeList = this.sysDictionaryApiService.getKvList(codeGrpCd, CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());
        view.addObject("sysCodeList", sysCodeList);

        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "toMainPage", " 跳转到第三方征信风控配置主表信息页面.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return view;
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object initRiskMList(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initRiskMList", " 初始化列表.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String sysCd = request.getParameter("sysCd");//系统代码
        String orgCd = request.getParameter("orgCd");//组织机构代码
        String cfgNm = request.getParameter("cfgNm");//配置名称
        String cfgCd = request.getParameter("cfgCd");//配置编码
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        RskCtrlCfgMQC qc = new RskCtrlCfgMQC();
        if (StringUtils.isNotEmpty(sysCd)) {
            qc.setSysCd(sysCd);
        }
        if (StringUtils.isNotEmpty(orgCd)) {
            qc.setOrgCd(orgCd);
        }
        if (StringUtils.isNotEmpty(cfgNm)) {
            qc.setCfgNm(cfgNm);
        }
        if (StringUtils.isNotEmpty(cfgCd)) {
            qc.setCfgCd(cfgCd);
        }
        page.setCondition(qc);

        Pager pager = this.rskCtrlCfgService.searchListPage(page);
        List<RskCtrlCfgMVO> list = (List<RskCtrlCfgMVO>) pager.getResultList();
        ListPageVO<RskCtrlCfgMVO> listPage = new ListPageVO<RskCtrlCfgMVO>(list, pager.getTotalCount());
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initRiskMList", " 初始化列表.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }

    /**
     * 初始化公司信息子表列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/cfgDInitList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object initRiskCfgDList(HttpServletRequest request, HttpServletResponse response) {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initRiskCfgDList", " 初始化公司信息子表列表.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String sysCd = request.getParameter("sysCd");//系统代码
        String orgCd = request.getParameter("orgCd");//组织机构代码
        String cfgCd = request.getParameter("cfgCd");//配置编码
        RskCtrlCfgDQC qc = new RskCtrlCfgDQC();
        if (StringUtils.isNotEmpty(sysCd)) {
            qc.setSysCd(sysCd);
        }
        if (StringUtils.isNotEmpty(orgCd)) {
            List<String> list = new ArrayList<String>();
            list.add(orgCd);
            qc.setOrgCdList(list);
        }
        if (StringUtils.isNotEmpty(cfgCd)) {
            List<String> list = new ArrayList<String>();
            list.add(cfgCd);
            qc.setCfgCdList(list);
        }
        List<RskCtrlCfgDVO> list = this.rskCtrlCfgService.searchListSon(qc);
        ListPageVO<RskCtrlCfgDVO> listPage = new ListPageVO<RskCtrlCfgDVO>(list, list.size());
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "initRiskCfgDList", " 初始化公司信息子表列表.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object addCfgM(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addCfgM", " 新增.请求参数：" + CurrentThreadContext.getCurrentUserName());
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        RskCtrlCfgMVO entity = new RskCtrlCfgMVO();
        try {
            entity = this.getRequestParamForRskAdd(request);//获取参数
            Long id = this.rskCtrlCfgService.add(entity);
            result.setData(id);
            BaseLogUtils.info(logger, "addCfgM", "新增风控配置主表信息成功,ID:"+id+".DATA:"+ JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addCfgM", "新增风控配置主表信息失败.DATA:"+JSONObject.toJSONString(entity)+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "addCfgM", "新增风控配置主表信息失败,系统错误.DATA:"+JSONObject.toJSONString(entity)+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addCfgM", " 新增.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 新增子表数据
     */
    @RequestMapping(value = "/addSON.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object addCfgD(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addCfgD", " 新增子表数据.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        RskCtrlCfgDVO entity = new RskCtrlCfgDVO();
        try {
            entity = this.getRequestParamForRskSONAdd(request);//获取参数
            Long id = this.rskCtrlCfgService.add(entity);
            result.setData(id);
            BaseLogUtils.info(logger, "addCfgD", "新增风控配置子表信息成功,ID:"+id+".DATA:"+ JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addCfgD", "新增风控配置子表信息失败.DATA:"+JSONObject.toJSONString(entity)+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "addCfgD", "新增风控配置子表信息失败,系统错误.DATA:"+JSONObject.toJSONString(entity)+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "addCfgD", " 新增子表数据.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object modifyCfgM(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyCfgM", " 修改.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
        RskCtrlCfgMVO entity = new RskCtrlCfgMVO();
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifyCfgM", "修改风控配置主表信息,主键参数为空！.ID:"+id, CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            entity = this.getRequestParamForRskModify(request);
            entity.setId(Long.valueOf(id));
            boolean success = this.rskCtrlCfgService.modify(entity);
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyCfgM", "修改风控配置主表信息失败.DATA:"+JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifyCfgM", "修改风控配置主表信息成功.DATA:"+JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            }
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifyCfgM", "修改风控配置主表信息失败.DATA:"+JSONObject.toJSONString(entity)+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifyCfgM", "修改风控配置主表信息失败,系统错误.DATA:"+JSONObject.toJSONString(entity)+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyCfgM", " 修改.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modifySON.do", method = { RequestMethod.POST })
    @ResponseBody
    public Object modifyCfgD(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyCfgD", " 修改风控配置子表信息.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES,SysLogConstant.LOG_CMM_UPDATE_SUCC);
        RskCtrlCfgDVO entity = new RskCtrlCfgDVO();
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifyD", "修改风控配置子表信息,主键参数为空！.ID:"+id, CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            entity = this.getRequestParamForRskSONModify(request);
            entity.setId(Long.valueOf(id));
            boolean success = this.rskCtrlCfgService.modify(entity);
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyD", "修改风控配置子表信息失败.DATA:"+JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifyD", "修改风控配置子表信息成功.DATA:"+JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
            }
        }catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifyD", "修改风控配置子表信息失败.DATA:"+JSONObject.toJSONString(entity)+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifyD", "修改风控配置子表信息失败,系统错误.DATA:"+JSONObject.toJSONString(entity)+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyD", " 修改风控配置子表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改风控配置主表状态
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modifySts.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object modifySts(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifySts", " 修改风控配置主表状态.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        String isValid = request.getParameter("isValid");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifySts", "修改风控配置主表状态信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlCfgService.modifyRMIsvalid(Long.valueOf(id), Integer.parseInt(isValid));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "modifySts", "修改风控配置主表状态失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifySts", "修改风控配置主表状态成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifySts", "修改风控配置主表状态失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifySts", "修改风控配置主表状态失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifySts", " 修改风控配置主表状态.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改风控配置子表状态
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modifySONSts.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object modifySONSts(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifySONSts", " 修改风控配置子表状态.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        String isValid = request.getParameter("isValid");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifySONSts", "修改风控配置子表状态信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlCfgService.modifyRDIsvalid(Long.valueOf(id), Integer.parseInt(isValid));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "modifySONSts", "修改风控配置子表状态失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifySONSts", "修改风控配置子表状态成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifySONSts", "修改风控配置子表状态失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifySONSts", "修改风控配置子表状态失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifySONSts", " 修改风控配置子表状态.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 修改风控配置子表验证状态
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modifyCheck.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object modifyCheck(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyCheck", " 修改风控配置子表验证状态.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        String isCheck = request.getParameter("isCheck");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "modifyCheck", "修改风控配置子表验证状态失败,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlCfgService.modifyRDIsCheck(Long.valueOf(id), Integer.parseInt(isCheck));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "modifyCheck", "修改风控配置子表验证状态失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "modifyCheck", "修改风控配置子表验证状态失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "modifyCheck", "修改风控配置子表验证状态失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "modifyCheck", "修改风控配置子表验证状态失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "modifyCheck", " 修改风控配置子表验证状态.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeById.do", method = {RequestMethod.GET })
    @ResponseBody
    public DataResultVO removeCfgMById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "removeCfgMById", " 删除数据.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "removeCfgMById", "删除风控配置主表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlCfgService.removeById(Long.valueOf(id));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.info(logger, "removeCfgMById", "删除风控配置主表信息失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "removeCfgMById", "删除风控配置主表信息成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "removeCfgMById", "删除风控配置主表信息失败,ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeCfgMById", "删除风控配置主表信息失败,系统错误.ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "removeCfgMById", " 删除数据.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeSONById.do", method = {RequestMethod.GET })
    @ResponseBody
    public DataResultVO removeCfgDById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "removeSONById", " 删除风控配置子表信息.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "removeCfgDById", "删除风控配置子表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            boolean success = this.rskCtrlCfgService.removeSONById(Long.valueOf(id));
            if(!success){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.info(logger, "removeCfgDById", "删除风控配置子表信息失败,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                BaseLogUtils.info(logger, "removeCfgDById", "删除风控配置子表信息成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "removeCfgDById", "删除风控配置子表信息失败,ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeCfgDById", "删除风控配置子表信息失败,系统错误.ID:"+id+".ERROR:"+ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "removeSONById", " 删除风控配置子表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object getCfgMById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "getCfgMById", " 获取风控配置主表信息.请求参数：" + CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "getCfgMById", "获取风控配置主表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            RskCtrlCfgMVO vo = this.rskCtrlCfgService.selectById(Long.valueOf(id));
            if(null == vo){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getCfgMById", "获取风控配置主表信息不存在,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                result.setData(vo);
                BaseLogUtils.info(logger, "getCfgMById", "获取风控配置主表信息成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "getCfgMById", "获取风控配置主表信息失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getCfgMById", "获取风控配置主表信息失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "getCfgMById", " 获取风控配置主表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getSONById.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object getCfgDById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        Long startTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "getCfgDById", " 获取风控配置主表信息.请求参数：" +  CurrentThreadContext.getCurrentUserName());
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if(StringUtils.isEmpty(id)){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "getCfgDById", "获取风控配置主表信息,主键参数为空！", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            RskCtrlCfgDVO vo = this.rskCtrlCfgService.selectSONById(Long.valueOf(id));
            if(null == vo){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getCfgDById", "获取风控配置主表信息不存在,ID:"+id, CurrentThreadContext.getCurrentUserName());
            } else {
                result.setData(vo);
                BaseLogUtils.info(logger, "getCfgDById", "获取风控配置主表信息成功,ID:"+id, CurrentThreadContext.getCurrentUserName());
            }
        }catch(BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "getCfgDById", "获取风控配置主表信息失败,ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }catch(Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getCfgDById", "获取风控配置主表信息失败,系统错误.ID:"+id+".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        Long endTm = System.currentTimeMillis();
        BaseLogUtils.info(logger, "getCfgDById", " 获取风控配置主表信息.耗时：" + (endTm-startTm), CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 获取征信请求参数(新增)
     * @param request 请求
     * @return
     */
    private RskCtrlCfgMVO getRequestParamForRskAdd(HttpServletRequest request)throws BaseException{
        RskCtrlCfgMVO rskCtrlMVO = this.getRequestParamForRsk(request);
        rskCtrlMVO.setCrtTm(new Date());
        rskCtrlMVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        return rskCtrlMVO;
    }

    /**
     * 获取征信接口请求参数(新增)
     * @param request 请求
     * @return
     */
    private RskCtrlCfgDVO getRequestParamForRskSONAdd(HttpServletRequest request)throws BaseException{
        RskCtrlCfgDVO rskCtrlCfgDVO = this.getRequestParamForRskSON(request);
        rskCtrlCfgDVO.setCrtTm(new Date());
        rskCtrlCfgDVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        return rskCtrlCfgDVO;
    }

    /**
     * 获取征信请求参数(修改)
     * @param request 请求
     * @return
     */
    private RskCtrlCfgMVO getRequestParamForRskModify(HttpServletRequest request)throws BaseException{
        RskCtrlCfgMVO rskCtrlCfgMVO = this.getRequestParamForRsk(request);
        rskCtrlCfgMVO.setMdfTm(new Date());
        rskCtrlCfgMVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        return rskCtrlCfgMVO;
    }

    /**
     * 获取征信接口请求参数(修改)
     * @param request 请求
     * @return
     */
    private RskCtrlCfgDVO getRequestParamForRskSONModify(HttpServletRequest request)throws BaseException{
        RskCtrlCfgDVO rskCtrlCfgDVO = this.getRequestParamForRskSON(request);
        rskCtrlCfgDVO.setMdfTm(new Date());
        rskCtrlCfgDVO.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        return rskCtrlCfgDVO;
    }

    /**
     * 获取配置主表参数信息
     * @param request
     * @return
     * @throws BaseException
     */
    private RskCtrlCfgMVO getRequestParamForRsk(HttpServletRequest request)throws BaseException{
        String sysCd = request.getParameter("sysCd");//系统代码
        String orgCd = request.getParameter("orgCd");//组织机构代码
        String cfgNm = request.getParameter("cfgNm");//配置名称
        String cfgCd = request.getParameter("cfgCd");//配置编码
        String isValid = request.getParameter("isValid");//是否启用

        RskCtrlCfgMVO rskCtrlMVO = new RskCtrlCfgMVO();
        rskCtrlMVO.setSysCd(sysCd.trim());
        rskCtrlMVO.setOrgCd(orgCd.trim());
        rskCtrlMVO.setCfgNm(cfgNm.trim());
        rskCtrlMVO.setCfgCd(cfgCd.trim());
        rskCtrlMVO.setIsValid(Integer.parseInt(isValid));
        return rskCtrlMVO;
    }

    /**
     * 获取配置子表参数信息
     * @param request
     * @return
     * @throws BaseException
     */
    private RskCtrlCfgDVO getRequestParamForRskSON(HttpServletRequest request)throws BaseException{
        String sysCd = request.getParameter("sysCd");//系统代码
        String orgCd = request.getParameter("orgCd");//组织机构代码
        String cfgCd = request.getParameter("cfgCd");//配置编码
        String datNm = request.getParameter("datNm");//子配置名称
        String cfgDtlCd = request.getParameter("cfgDtlCd");//子配置名称
        String datDesc = request.getParameter("datDesc");//子配置描
        String isValid = request.getParameter("isValid");//是否启用
        String isCheck = request.getParameter("isCheck");//是否验证

        RskCtrlCfgDVO rskCtrlCfgDVO = new RskCtrlCfgDVO();
        rskCtrlCfgDVO.setSysCd(sysCd.trim());
        rskCtrlCfgDVO.setOrgCd(orgCd.trim());
        rskCtrlCfgDVO.setCfgCd(cfgCd.trim());
        rskCtrlCfgDVO.setDatNm(datNm.trim());
        rskCtrlCfgDVO.setCfgDtlCd(cfgDtlCd.trim());
        rskCtrlCfgDVO.setDatDesc(datDesc.trim());
        rskCtrlCfgDVO.setIsValid(Integer.parseInt(isValid));
        rskCtrlCfgDVO.setIsCheck(Integer.parseInt(isCheck));
        return rskCtrlCfgDVO;
    }
}
